Skip to content

mcp: Allow registration of custom JSON-RPC methods#956

Open
guglielmo-san wants to merge 5 commits into
mainfrom
guglielmoc/SEP-2133_extensions_framework
Open

mcp: Allow registration of custom JSON-RPC methods#956
guglielmo-san wants to merge 5 commits into
mainfrom
guglielmoc/SEP-2133_extensions_framework

Conversation

@guglielmo-san
Copy link
Copy Markdown
Contributor

@guglielmo-san guglielmo-san commented May 13, 2026

Description

This PR introduces support for custom (non-standard) JSON-RPC methods in the MCP Go SDK.
This feature enables servers to handle arbitrary JSON-RPC methods and clients to invoke them, all while maintaining full type safety and integrating seamlessly with the SDK's existing middleware and session management.

  • Server-Side Registration: Added AddReceivingCustomMethod to allow servers to register handlers for custom methods. Incoming requests are automatically unmarshaled into user-defined parameter structs.
  • Client-Side Calling: Added AddSendingCustomMethod which returns a strongly-typed caller function that clients can use to invoke custom methods and receive strongly-typed results.
  • Helper Structs: Provided ParamsBase and ResultBase for users to embed in their custom structs. This allows them to easily satisfy the SDK's internal Params and Result interfaces.

Fixes #954

@guglielmo-san guglielmo-san marked this pull request as ready for review May 13, 2026 13:21
Copy link
Copy Markdown
Contributor

@maciej-kisiel maciej-kisiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding @jba who was responding in similar discussions regarding custom notifications. He has deeper understanding than me.

Comment thread mcp/client.go
return serverMethodInfos
}
infos := make(map[string]methodInfo, len(serverMethodInfos)+len(cs.client.customSendMethods))
maps.Copy(infos, serverMethodInfos)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit unnecessary to construct the map on every call. Maybe it's worth moving the source of truth map containing all methods under an appropriate type (Client?).

Comment thread mcp/client.go
defer c.mu.Unlock()
c.customSendMethods[method] = mi

return func(ctx context.Context, cs *ClientSession, params P) (R, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure exposing this via a return value will cover all the use cases. Most of the users of this will probably be extensions, which will do the registration for the developer. Not sure how easy it will be to propagate this.

Comment thread mcp/streamable.go
return nil, err
}
transport.connection.server = server
transport.connection.toolLookup = server.getServerTool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: after this we could remove the toolLookup field and use the server.

@maciej-kisiel maciej-kisiel requested a review from jba May 15, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow registration of custom JSON-RPC methods

2 participants